<template>
	<view class="content">
		<view class="top-block">
			<view class="classify-tab-block">
				<view class="tab-content" style="flex-grow: 1;">
					<view :class="tabActive==0?'active':''" class="tab-item" @click="tabActive=0">全部</view>
					<view @click="tabActive=item.id" :class="tabActive==item.id?'active':''" class="tab-item"
						v-for="(item,index) in tabList" :key="item.id">{{item.name}}</view>
				</view>
			</view>
		</view>
		<view class="info-block">
			<view class="input-block">
				<view class="iconfont icon-sousuo" @click="getList(true)"></view>
				<input placeholder="请输入搜索关键字..." v-model="keyWords" @confirm="search"
					placeholder-style="color:#157DFA;font-size:30rpx;" />
			</view>
			<template v-if="list.length>0">
				<view class="info-list" v-for="(item,index) in list" :key="item.id"
					@click="navigate('/page_other/activity/detail?id='+item.id+'&type='+item.state)">
					<view class="info-item">
						<image :src="item.coverImage" class="img" mode="aspectFill"></image>
						<view class="state-item2" v-if="item.state==1">
							<image src="../../static/images/mine/progress.png" class="progress-img"></image>
							<view class="progress">报名中</view>
						</view>
						<view class="state-item" v-if="item.state==2">
							<image src="../../static/images/mine/progress.png" class="progress-img"></image>
							<view class="progress">进行中</view>
						</view>
						<view class="state-item1" v-if="item.state==3">
							<image src="../../static/images/mine/end.png" class="progress-img"></image>
							<view class="progress">已结束</view>
						</view>
						<view class="right-item">
							<view class="title">{{item.title}}</view>
							<view class="count">{{item.description}}</view>
							<view class="count">{{item.enrollment}}人已参加活动</view>
						</view>
					</view>
				</view>
			</template>
			<view v-if="list.length>0&&!listConf.more" style="text-align: center;margin-top: 30rpx;">没有更多了哦</view>
			<view v-else style="text-align: center;margin-top: 30rpx;">暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {
		getActivityListApi,
		getTableListApi
	} from '@/api/activity.js'
	import {
		isMore
	} from '@/util/util.js'
	import {
		getStorage
	} from '@/util/auth.js';
	export default {
		data() {
			return {
				keyWords: '',
				tabActive: 0, //顶部tab
				tabList: [],
				listConf: {
					page: 1,
					limit: 10,
					more: true,
				},
				list: []
			}
		},
		watch: {
			tabActive: {
				handler() {
					this.getList(true)
					this.keyWords = ''
				}
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			search() {
				this.getList(true)
			},
			getTabList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getTableListApi({}).then(data => {
					uni.hideLoading()
					this.tabList = data
				}).catch(() => {
					uni.hideLoading()
				})
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getActivityListApi({
					page: this.listConf.page,
					limit: this.listConf.limit,
					type: this.tabActive,
					title: this.keyWords,
					villageId: getStorage('villageId')
				}).then(data => {
					uni.hideLoading()
					let list = data.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.listConf.more = isMore(this.listConf.page, this.listConf.limit, data.count);
				}).catch(() => {
					uni.hideLoading()
				})
			}

		},
		onReachBottom() {
			if (this.listConf.more) {
				this.listConf.page++;
				this.getList()
			}
		},
		onLoad() {
			this.getList(true)
			this.getTabList()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.top-block {
			width: 100%;
			padding: 30rpx;
			display: flex;
			flex-direction: column;
			background: #157DFA;
			height: 200rpx;

			.classify-tab-block {
				width: 100%;
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				position: relative;
				margin-top: 20rpx;

				.tab-content {
					display: flex;
					flex-direction: row;
					//justify-content: space-around;
					overflow-x: scroll;

					.tab-item {
						padding: 10rpx 15rpx;
						font-weight: bold;
						font-size: 30rpx;
						margin-right: 20rpx;
						flex: none;
						color: #fff;
					}

					.tab-item.active {
						border-bottom: 3px solid #fff;
						font-size: 32rpx;
					}
				}

				.iconfont {
					font-size: 32rpx;
					font-weight: bold;
					color: #fff;
				}
			}
		}

		.info-block {
			display: flex;
			flex-direction: column;
			background: #F5F9FC;
			border-radius: 40rpx;
			margin-top: -50rpx;
			height: auto;
			position: relative;
			padding: 30rpx;
			min-height: 70vh;

			.input-block {
				//width: calc(100% - 60rpx);
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				background: #fff;
				border-radius: 40rpx;
				padding: 0 10rpx;
				height: 80rpx;
				background: #CADFFA;

				.iconfont {
					flex-grow: 0;
					color: #157DFA;
					padding-left: 30rpx;
					font-size: 36rpx;
				}

				input {
					flex-grow: 1;
					font-size: 30rpx;
					color: #157DFA;
					margin: 0 10rpx;
				}
			}

			.info-list {
				background: #fff;
				box-shadow: 0 0 18rpx 0 #dddddd;
				display: flex;
				flex-direction: column;
				padding: 30rpx;
				margin-top: 30rpx;
				border-radius: 20rpx;

				.info-item {
					display: flex;
					align-items: center;

					.img {
						width: 170rpx;
						height: 170rpx;
						border-radius: 20rpx;
						background-color: #F5F9FC;
						margin-right: 30rpx;
					}

					.state-item {
						width: 140rpx;
						height: 44rpx;
						border-radius: 30rpx;
						background: #027BFE;
						display: flex;
						flex-direction: row;
						align-items: center;
						justify-content: center;
						position: absolute;
						margin-top: 110rpx;
						margin-left: 10rpx;

						.progress-img {
							width: 24rpx;
							height: 30rpx;
							margin-right: 10rpx;
						}

						.progress {
							color: #fff;
							font-size: 22rpx;
						}
					}

					.state-item1 {
						width: 140rpx;
						height: 44rpx;
						border-radius: 30rpx;
						background: #AAAAAA;
						display: flex;
						flex-direction: row;
						align-items: center;
						justify-content: center;
						position: absolute;
						margin-top: 110rpx;
						margin-left: 10rpx;

						.progress-img {
							width: 24rpx;
							height: 30rpx;
							margin-right: 10rpx;
						}

						.progress {
							color: #fff;
							font-size: 22rpx;
						}
					}

					.state-item2 {
						width: 130rpx;
						height: 44rpx;
						border-radius: 30rpx;
						background: #39E274;
						display: flex;
						flex-direction: row;
						align-items: center;
						justify-content: center;
						position: absolute;
						margin-top: 110rpx;
						margin-left: 10rpx;

						.progress-img {
							width: 24rpx;
							height: 30rpx;
							margin-right: 10rpx;
						}

						.progress {
							color: #fff;
							font-size: 22rpx;
						}
					}

					.right-item {
						width: calc(100% - 200rpx);

						.title {
							width: 100%;
							font-size: 32rpx;
							font-weight: bold;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.count {
							color: #747474;
							font-size: 28rpx;
							margin-top: 14rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}
				}
			}
		}
	}
</style>